/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ThreadClient;

import InterfaceClient.JLocationList;
import Packets.pkValue;
import StaticClass.ArrSocket;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.GZIPOutputStream;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
//import sun.java2d.pipe.ValidatePipe;
//import sun.security.jca.JCAUtil;

/**
 *
 * @author Oho
 */
public class ThreadFile_Tree extends Thread {

    Socket sk = null;
    int port;

    public ThreadFile_Tree(int port) {
        this.port = port;
    }

    public ThreadFile_Tree(Socket sk) {
        this.sk = sk;
    }
    ObjectInputStream inp = null;
    ObjectOutputStream outp = null;
    ComboBoxModel md = null;

    public void ThreadRead() throws FileNotFoundException, IOException, IOException, ClassNotFoundException {
        if (inp == null) {
            inp = new ObjectInputStream(sk.getInputStream());

        }
        // if(outp==null)

        pkValue name = (pkValue) inp.readObject();
        //  JDriveCombo2 cbb = new JDriveCombo2();
        if (md == null) {
            md = new DefaultComboBoxModel(File.listRoots());
            outp.writeObject(md);
            outp.flush();
        }
        JLocationList jList1Files = new JLocationList(JLocationList.FILETYPE_FILE, false, null);
        JLocationList jList1Folder = new JLocationList(JLocationList.FILETYPE_FOLDER, false, jList1Files, null);
        jList1Files.setParentFile(name.getObj().toString());
        jList1Folder.setParentFile(name.getObj().toString());
        //JDriveCombo jComboBox1 = new JDriveCombo2(jList1Folder);
        //jComboBox1.addItemListener(new ItemListener() {

        //  @Override
        //public void itemStateChanged(ItemEvent e) {

        //  jList1Files.setParentFile(e.getItemSelectable().toString());
        //jList1Folder.setParentFile(e.getItemSelectable().toString());
        //}
        //});
        //combo = new JDriveCombo2(jList1Folder);






        outp.writeObject(jList1Files);
        outp.flush();

        outp.writeObject(jList1Folder);

        outp.flush();
  
//        pkValue pk = (pkValue) inp.readObject();
//        String value = (String) pk.getObj();
//        jList1Folder.setParentFile(value);
//          
//        jList1Files.setParentFile(value);
//         
//       // jList2Files .setParentFile(value);
//        outp.writeObject(jList1Files);
        // outp.flush();
        //String value = inp.readObject().toString();
        // jList1Files.setParentFile(value);


        // JLocationList2 jList2Files = new JLocationList2(JLocationList2.FILETYPE_FILE, false, null);
        //jList2Files.setParentFile(value);
        //  jList1Folder.setParentFile(value);
        // outp.writeObject(jList2Files);   //     outp.writeObject(jList1Files);

        // outp.flush();

    }

    @Override
    public void run() {
        try {
            outp = new ObjectOutputStream(sk.getOutputStream());
            while (true) {
                try {
                    try {
                        //while (true) {
                        //
                        //

                        ThreadRead();
                        // inp.close();
                        //} catch (FileNotFoundException ex) {
                        //  Logger.getLogger(ThreadFile.class.getName()).log(Level.SEVERE, null, ex);
                        ///} catch (IOException ex) {
                        //
                        //}



                        //}
                    } catch (ClassNotFoundException ex) {
                        Logger.getLogger(ThreadFile_Tree.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } catch (FileNotFoundException ex) {
                    Logger.getLogger(ThreadFile_Tree.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(ThreadFile_Tree.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        } catch (IOException ex) {
            Logger.getLogger(ThreadFile_Tree.class.getName()).log(Level.SEVERE, null, ex);
        }


    }
}
